#!/usr/bin/env python
#-*- coding: utf-8 -*-
#
# Copyright 2013 Antoine Drouin (poinix@gmail.com)
#
# This file is part of PAT.
#
#    PAT is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    PAT is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with PAT.  If not, see <http://www.gnu.org/licenses/>.
#

"""
 
"""

import numpy as np
import scipy.integrate
import matplotlib.pyplot as plt

import pat.vehicles.fixed_wing.dynamic_model_longitudinal as dm


np.set_printoptions(precision=2, suppress=True, linewidth=160)

model = dm.DynamicModel()
Xe, Ue = model.trim()
print "Xe {:s}\nUe {:s}".format(Xe, Ue)

A, B = model.jacobian(Xe, Ue)
print "A\n{:s}\nB\n{:s}".format(A, B)

w, M = np.linalg.eig(A)
print "w {:s}\nM\n{:s}".format(w, M)

time = np.arange(0., 180., 0.01)
X0 = np.array(Xe)
X0[dm.sv_va] += 2

X = scipy.integrate.odeint(dm.dyn, X0, time, args=(Ue, model.P, ))

model.plot_trajectory(time, X)
plt.show()
